<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
	exclude-result-prefixes="">
 	<xsl:template match="object">
		<resource>
			<instance>
				<xsl:apply-templates />
				<holding type="online" available="True">
					<xsl:call-template name="url" />
					<xsl:call-template name="threshold" />
				</holding>
			</instance>
		</resource>
	</xsl:template>
	
	<!-- Suppress all unmatched text/attributes -->
	<xsl:template match="text()|@*"/>
	
	<xsl:template match="identifier[@type='issn']">
		<issn><xsl:value-of select="."/></issn>
	</xsl:template>
	<xsl:template match="identifier[@type='isbn']">
		<isbn><xsl:value-of select="."/></isbn>
	</xsl:template>
	<xsl:template match="identifier[@type='lccn']">
		<lccn><xsl:value-of select="."/></lccn>
	</xsl:template>
	<xsl:template match="identifier[@type='object_id']">
		<identifier type="sfx_object_id"><xsl:value-of select="."/></identifier>
	</xsl:template>
	<xsl:template match="title[not(@type)]">
		<title><xsl:value-of select="." /></title>
	</xsl:template>
	<xsl:template match="category">
		<subject><xsl:value-of select="."/></subject>
	</xsl:template>
	<xsl:template match="local_attribute">
		<description><xsl:value-of select="."/></description>
	</xsl:template>
	<xsl:template match="publisher">
		<publisher><xsl:value-of select="."/>, <xsl:value-of select="../publisher_place"/></publisher>
	</xsl:template>
	<xsl:template match="date[@type='publication']">
		<date type="publication"><xsl:value-of select="."/></date>
	</xsl:template>
	<xsl:template match="object_type">
		<type><xsl:value-of select="."/></type>
		<format><xsl:value-of select="."/></format>
	</xsl:template>
	<xsl:template match="language">
		<language><xsl:value-of select="."/></language>
	</xsl:template>
	
	<xsl:template name="threshold">
		<xsl:if test="./threshold[not(@type)]">
			<threshold><xsl:value-of select="./threshold[not(@type)]" /></threshold>
		</xsl:if>
	</xsl:template>
	
	<xsl:template name="url">
		<sfxUrl>
			<xsl:attribute name="title"><xsl:value-of select="./target_public_name" /></xsl:attribute>
			<xsl:choose>
				<xsl:when test="./identifier[@type='issn']">
				&amp;rft.issn=<xsl:value-of select="./identifier[@type='issn']" />&amp;rft.object_portfolio_id=<xsl:value-of select="./identifier[@type='object_portfolio']" />
				</xsl:when>
				<xsl:otherwise>
				&amp;rtf.object_id=<xsl:value-of select="./identifier[@type='object_id']" />
				</xsl:otherwise>
			</xsl:choose>
		</sfxUrl>
	</xsl:template>
</xsl:stylesheet>	
